package com.airsystem.pos.bengkel.model;

import java.awt.GridBagLayout;
import java.util.Calendar;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import com.airsystem.pos.bengkel.component.DesktopFrame;
import com.airsystem.pos.bengkel.entity.wrapper.TagihanWrapper;
import com.airsystem.pos.bengkel.util.DateUtil;

/**
 * @author Fanny Irawan Sutawanir (fannyirawans@gmail.com)
 */
public class MasterBillingDetailModel extends DesktopFrame {
	protected final int currentMonth;

	protected int currentYear;

	protected int row = 0;

	private static final String[] COLUMNS = { "Jenis Tagihan", "Biaya Tagihan/bln" };

	protected GridBagLayout baseLayout = new GridBagLayout();
	protected GridBagLayout panelLayout = new GridBagLayout();

	protected JScrollPane tablebillingScroll = new JScrollPane();

	protected JPanel basePanel = new JPanel();
	protected JPanel buttonPanel = new JPanel();
	protected JPanel fieldPanel = new JPanel();

	protected JLabel periodeLabel = new JLabel();
	protected JLabel jenisLabel = new JLabel();
	protected JLabel biayaLabel = new JLabel();
	protected JLabel totalLabel = new JLabel();

	protected JTextField biayaField = new JTextField();
	protected JTextField totalField = new JTextField();

	protected JComboBox bulanCombo = new JComboBox();
	protected JComboBox tahunCombo = new JComboBox();
	protected JComboBox jenisCombo = new JComboBox();

	protected JTable tableTagihan = new JTable();

	protected JButton searchButton = new JButton();
	protected JButton addButton = new JButton();
	protected JButton saveButton = new JButton();
	protected JButton updateButton = new JButton();
	protected JButton deleteButton = new JButton();
	protected JButton cancelButton = new JButton();

	protected DefaultTableModel tableModel = new DefaultTableModel(new Object[][] {}, COLUMNS) {
		boolean[] canEdit = new boolean[] { false, false };

		public boolean isCellEditable(int rowIndex, int columnIndex) {
			return canEdit[columnIndex];
		}
	};

	protected TagihanWrapper tagihanWrapper;

	public MasterBillingDetailModel() {
		super();

		Calendar calendar = Calendar.getInstance();
		currentMonth = calendar.get(Calendar.MONTH) + 1;

		int currentYear = calendar.get(Calendar.YEAR);
		bulanCombo.addItem("-- PILIH BULAN --");

		for (String item : DateUtil.getMonth()) {
			bulanCombo.addItem(item);
		}

		tahunCombo.addItem("-- PILIH TAHUN --");
		int index = 0;

		for (String item : DateUtil.getYear()) {
			if (item.equals(String.valueOf(currentYear))) {
				this.currentYear = index + 1;
			}
			tahunCombo.addItem(item);

			index++;
		}
	}

	public String getPeriode() {
		StringBuilder periodeBuilder = new StringBuilder(bulanCombo.getSelectedItem().toString());
		periodeBuilder.append("/");
		periodeBuilder.append(tahunCombo.getSelectedItem().toString());

		return periodeBuilder.toString();
	}
}